require('./PageEngedit.styl');


import {Boxs, Field, Group, Tab, Table, Toast} from 'saltui';
import {Component} from 'react'
import {Control} from 'react-keeper'

const {YCZAZ_URL} = require(`./../../config/${ENV}.json`);
const HBox = Boxs.HBox;
const Box = Boxs.Box;

class Page extends Component {

  constructor(props) {
    super(props);
    let t = this;

    this.state = {
      activeIndex: 0,
      eng: {},
      sgry: {
        data: []
      },
      jlry: {
        data: []
      },
      columns: [
        {
          dataKey: 'ryName', title: '姓名', align: 'center', render:
          function (key, item) {
            return <div className="emp-name" onClick={t.onEmpClick.bind(t, item.empId)}>{item.ryName}</div>
          }
        },
        {dataKey: 'ryGw', title: '岗位', align: 'center', width: '0.45'},
        {dataKey: 'ryZsmc', title: '证件名称', align: 'center', width: '0.3'},
        {dataKey: 'ryNum', title: '证件号', align: 'center', width: '0.5'},
      ],
    };
  }

  onEmpClick(obj) {

    // window.location = YCZAZ_URL + 'gkcx/rycx/editNew_move.seam?empId=' + obj;

    dd.biz.util.openLink({
      url: YCZAZ_URL + 'gkcx/rycx/editNew_move.seam?empId=' + obj,
      onSuccess: function (result) {
        Toast.hide(function () {
        });
      },
      onFail: function (err) {
        alert(JSON.stringify(err));
      }
    });
  }

  onOrgClick(obj) {

    // window.location = YCZAZ_URL + 'gkcx/qycx/editNew_move.seam?cioId=' + obj;


    dd.biz.util.openLink({
      url: YCZAZ_URL + 'gkcx/qycx/editNew_move.seam?cioId=' + obj,
      onSuccess: function (result) {
        Toast.hide(function () {
        });
      },
      onFail: function (err) {
        alert(JSON.stringify(err));
      }
    });

  }


  //页签TAB切换事件
  onTabChange(obj) {
    console.log(obj);
    this.setState({
      activeIndex: obj.active,
    })

  }


  render() {
    let t = this;
    return (
      <div className="engedit">
        <Tab activeKey={'0'}>
          <Tab.Item title="监督工程">
            <Group>
              <Group.Head> 基本信息 </Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="施工许可证号">
                  <div>{t.state.eng.engCode}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="工程名称">
                  <div>{t.state.eng.engName}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="建设地点">
                  <div>{t.state.eng.engAddress}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="建设规模">
                  <div>{t.state.eng.engJsgm}</div>
                </Field>
              </Group.List>
              <Group.Head>建设单位</Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="建设单位">
                  <div className="org-name"
                       onClick={this.onOrgClick.bind(this, t.state.eng.jsdwId)}>{t.state.eng.engJsdw}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="项目负责人">
                  <div>{t.state.eng.engJsdwFzr}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="电话">
                  <div>{t.state.eng.engJsdwTel}</div>
                </Field>
              </Group.List>
              <Group.Head>施工单位</Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="施工单位">
                  <div className="org-name"
                       onClick={this.onOrgClick.bind(this, t.state.eng.sgdwId)}>{t.state.eng.engSgdw}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="项目经理">
                  <div>{t.state.eng.engSgdwFzr}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="电话">
                  <div>{t.state.eng.engSgdwTel}</div>
                </Field>
              </Group.List>
              <Group.Head>监理单位</Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="监理单位">
                  <div className="org-name"
                       onClick={this.onOrgClick.bind(this, t.state.eng.jldwId)}>{t.state.eng.engJldw}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="项目总监">
                  <div>{t.state.eng.engJldwFzr}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="电话">
                  <div>{t.state.eng.engJldwTel}</div>
                </Field>
              </Group.List>
              <Group.Head>勘察单位</Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="勘察单位">
                  <div className="org-name"
                       onClick={this.onOrgClick.bind(this, t.state.eng.kcdwId)}>{t.state.eng.engKcdw}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="负责人">
                  <div>{t.state.eng.engKcdwFzr}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="电话">
                  <div>{t.state.eng.engKcdwTel}</div>
                </Field>
              </Group.List>
              <Group.Head>设计单位</Group.Head>
              <Group.List lineIndent={18}>
                <Field layout='h' label="设计单位">
                  <div className="org-name"
                       onClick={this.onOrgClick.bind(this, t.state.eng.sjdwId)}>{t.state.eng.engSjdw}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="负责人">
                  <div>{t.state.eng.engSjdwFzr}</div>
                </Field>
              </Group.List>
              <Group.List lineIndent={18}>
                <Field layout='h' label="电话">
                  <div>{t.state.eng.engSjdwTel}</div>
                </Field>
              </Group.List>
            </Group>
          </Tab.Item>
          <Tab.Item title="施工项目部">

            <Table
              columns={t.state.columns}
              data={t.state.sgry}
              hideSplitLine
              leftFixed={0}
            />


          </Tab.Item>
          <Tab.Item title="监理项目部">
            <Table
              columns={t.state.columns}
              data={t.state.jlry}
              hideSplitLine
              leftFixed={0}
            />

          </Tab.Item>
        </Tab>
      </div>
    );
  }


  componentWillMount() {
    this.setState({
      eng: Control.state,
      sgry: {
        data: Control.state.sgry
      },
      jlry: {
        data: Control.state.jlry
      }
    });


    dd.device.notification.hidePreloader();
    console.log(Control.state);
  }

  componentDidMount() {
    dd.biz.navigation.setTitle({
      title: '工程明细信息',//控制标题文本，空字符串表示显示默认文本
      onSuccess: function (result) {

      },
      onFail: function (err) {

      }
    });
  }
}

Page
  .contextTypes = {
  router: React.PropTypes.object.isRequired,
  location: React.PropTypes.object.isRequired,
};


export default Page;
